var loadModules = ['ngRoute', 'ngResource', 'ngAnimate', 'ui.router', 'ngDialog', 'ngFileUpload', 'angular-js-xlsx',
    'pascalprecht.translate', 'sz.moduleMain', 'sz.moduleUtils', 'sz.moduleCommon', 'sz.moduleResource',
    'sz.moduleFirm', 'sz.moduleAnalysis', 'sz.moduleLearningMap', 'sz.moduleBadge', 'sz.moduleQuiz', 'sz.moduleDynamicHtml',
    'sz.moduleDoor', 'sz.moduleUriEvent', 'sz.moduleForum', 'sz.moduleLanguage', 'sz.moduleOrganizationClient',
    'sz.moduleContent', 'ui.tree'];

var cambioWebManagement = angular.module('cambioWebEnterprise', loadModules);

cambioWebManagement.run(function (LanguageService, $rootScope, ConstantService, $state) {
    $rootScope.$on('$stateChangeStart', function (event, toState, toParams, fromState, fromParams) {
        if (toState.name !== "login" && toState.name !== "guide" && StringUtils.isNlOrUndOrEmpty(ConstantService.getItem("userId"))) {
            Alert.error(LanguageService.language('未登录或登录超时!'));
            event.preventDefault();
            $state.go("login");
        }
    });

    LanguageService.loadLanguage();
    /**
     *
     */
    var configAlert = function () {
        var infoConfig = {
            title: LanguageService.language('提示')
        };
        var successConfig = {
            text: LanguageService.language('操作成功'),
            title: LanguageService.language('成功')
        };
        var errorConfig = {
            title: LanguageService.language('失败')
        }
        var confirmConfig = {
            title: LanguageService.language('确认'),
            msg: LanguageService.language('是否要执行该操作？')
        }
        Alert.config(infoConfig, successConfig, errorConfig, confirmConfig, 'OK', 'Cancel');
    }

    configAlert();
});


cambioWebManagement.config(function ($urlRouterProvider, $locationProvider, $httpProvider, $stateProvider, $translateProvider) {
    $httpProvider.interceptors.push('ResponseErrorInterceptor');

    $locationProvider.html5Mode(false);
    $stateProvider
        .state('sz', {
            url: "/sz",
            abstract: true,
            templateUrl: "templates/Menu.html",
            controller: 'MenuController',
            resolve: {}
        });

    $urlRouterProvider.otherwise('/login?v=' + new Date().getTime());
    //国际化
    var lang = window.localStorage.lang || 'cn';
    $translateProvider.preferredLanguage(lang);
    $translateProvider.useStaticFilesLoader({
        prefix: 'lib/',
        suffix: '.json'
    });
});

